package org.shiro.session;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator;
import org.apache.shiro.session.mgt.eis.SessionIdGenerator;
import org.shiro.constant.RedisConstant;

import java.io.Serializable;

/** @author HKC */
public class ShiroSessionIdGenerator implements SessionIdGenerator {
  /** 实现SessionId生成 */
  @Override
  public Serializable generateId(Session session) {
    try {
      Serializable sessionId = new JavaUuidSessionIdGenerator().generateId(session);
      return String.format(RedisConstant.REDIS_PREFIX_LOGIN, sessionId);
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
}
